<!-- 工站库编辑器 右侧 工站信息 -->
<!--过站:OVERSTATION  测试:TEST 报工:TIMESHEET 老化:AGING  组装:ASSEMBLY 包装:PACKING -->
<template>
  <div class="box-card" :style="boxCardStyle">
    <el-collapse v-model="activeNames">
      <el-collapse-item title="工站信息" name="1">
        <el-tabs class="nav-tab" v-model="activeName">
          <el-tab-pane label="通用属性" name="1">
            <avue-form v-if="currentStationInfo && currentStationInfo.routeType" ref="baseInfoTabPane" v-model="currentStationInfo" :option="basicInfoOption">
              <template slot="isSkippable">
                <el-switch v-model="currentStationInfo.isSkippable" :disabled="readOnlyPage" @change="(value) => setCurrentStationProperty('isSkippable', value)"> </el-switch>
              </template>
            </avue-form>
            <div v-else><avue-form v-model="defaultStationInfo" :option="basicInfoOption"> </avue-form></div>
          </el-tab-pane>
          <el-tab-pane label="特征属性" name="2" v-if="currentStationInfo.routeType">
            <avue-form ref="specialInfoTabPane" v-model="currentStationInfo" :option="specialInfoOption">
              <template slot="isDeduct">
                <el-switch v-model="currentStationInfo.isDeduct" :disabled="readOnlyPage" @change="(value) => setCurrentStationProperty('isDeduct', value)"> </el-switch>
              </template>
              <template slot="deductType">
                <el-select
                  v-model="currentStationInfo.deductType"
                  placeholder="请选择 扣料类型"
                  :disabled="readOnlyPage"
                  @change="(value) => setCurrentStationProperty('deductType', value)"
                >
                  <el-option label="SMT扣料" value="SMT"> </el-option>
                  <el-option label="DIP扣料" value="DIP"> </el-option>
                </el-select>
              </template>
              <template slot="productPackingConfigName">
                <el-input placeholder="请选择 包装配置" v-model="currentStationInfo.productPackingConfigName" class="input-with-select" disabled>
                  <el-button slot="append" icon="el-icon-circle-close" v-if="currentStationInfo.productPackingConfigName" @click="clearProductPackingConfigName"></el-button>
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    @click="
                      openUserCommonModal({
                        type: 'packingConfig'
                      })
                    "
                  ></el-button>
                </el-input>
              </template>
              <template slot="keyPart">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="openEditNodeModal('keyPartConfig')"> 关键物料 </el-button>
                <KeyPartModal :config="keyPartConfig" @close="close('keyPartConfig')"></KeyPartModal>
              </template>
            </avue-form>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
      <el-collapse-item title="首工序定义" name="2">
        <avue-form ref="firstStepInfo" v-model="firstStep" :option="firstStepOption"> </avue-form>
      </el-collapse-item>
      <el-collapse-item title="追溯设置" name="3">
        <div class="traceContainer">
          <div class="title">工段追溯工序配置:</div>
          <el-row v-for="(section, index) in sectionAndRouteList" :key="index" :gutter="10" class="row">
            <el-col :span="8">
              <el-input v-model="section.sectionName" size="small" disabled placeholder="工段"></el-input>
            </el-col>
            <el-col :span="16">
              <el-select
                v-model="section.routeId"
                size="small"
                placeholder="请选择工序"
                style="width: 100%"
                popper-class="routePopper"
                @change="(value) => changeRoute(value, index)"
              >
                <el-option v-for="process in getRouteList(section.sectionId)" :key="process.routeId" :label="process.routeName" :value="process.routeId"> </el-option>
              </el-select>
            </el-col>
          </el-row>
        </div>
      </el-collapse-item>
      <el-collapse-item title="开线检查设置" name="4" v-show="activeName === '1'">
        <div class="sectionOnLinetitle">工段首工序开线检查设置:</div>
        <div class="sectionOnLineConfig" v-for="(item, index) in lineInspectionList" :key="index">
          <div class="sectionSwitch">
            <div style="width: 80px">{{ item.sectionName }}：</div>
            <el-switch v-model="item.isEnable" active-text="是" inactive-text="否" @change="sectionSwitchChange(item.isEnable, index)"></el-switch>
          </div>
          <el-button v-if="item.isEnable" type="primary" size="small" icon="el-icon-plus" @click="openEditCheckItem(index)">编辑检查项</el-button>
        </div>
      </el-collapse-item>
    </el-collapse>
    <commonPartConfig :config="commonPartConfig" @close="close('commonPartConfig')" @changeProcessMaterialControlList="changeProcessMaterialControlList"> </commonPartConfig>
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"> </common-modal-template>
    <global-modal-template :visibile.sync="visibile" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"> </global-modal-template>
    <!-- 上阶半成品 -->
    <part-master-model ref="prePartRef" @getSelectedRows="getSelectedRows" :key="timer + 1" @newKey="newKey"></part-master-model>
    <editCheckItem
      v-if="isShowCheckItemModal"
      ref="editCheckItemModalRef"
      :showModal="isShowCheckItemModal"
      :checkDetail="checkDetailData"
      @close="closeCheckItemModal"
      @submitCheckItem="submitCheckItem"
    ></editCheckItem>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import KeyPartModal from './modal/keyPartModal.vue'; // 关键物料信息弹窗;
import commonPartConfig from './modal/commonPartConfig.vue'; // 普通物料信息弹窗;
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import GlobalModalTemplate from '@/components/common-modal-template/global-modal-template.vue';
import { getPackingDetail, getSectionByPartId, getKeyMaterialConfigByRouteId, getKeyMaterialConfigByProcessId } from '@/api/product/productrouteManage';
import partMasterModel from './partMasterModel.vue';
import editCheckItem from './modal/editCheckItem.vue';

export default {
  components: {
    CommonModalTemplate,
    KeyPartModal,
    commonPartConfig,
    GlobalModalTemplate,
    partMasterModel,
    editCheckItem
  },
  props: {
    // 查看页面 只读
    readOnlyPage: {
      type: Boolean,
      default: false
    },
    productData: {
      type: Object,
      default: () => {}
    },
    sections: {
      type: Array,
      default: () => []
    },
    designer: {
      type: Object,
      default: () => {}
    },
    productProcessId: {
      type: String,
      default: ''
    },
    routeTypes: {
      type: Array,
      default: () => []
    },
    designerBoxHeight: {
      type: String
    },
    lineInspectionJson: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      activeNames: ['1', '2', '3', '4'],
      visibile: false,
      newProcessMaterialControlList: [],
      activeName: '1', //API基本信息显示Tabs
      // 右侧面板 基本信息 表单配置项
      defaultStationInfo: {
        routeName: '',
        routeType: '',
        isSkippable: false
      },
      basicInfoOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '160',
        menuSpan: 6,
        labelPosition: 'top',
        column: [
          {
            label: '工站名称',
            prop: 'routeName',
            span: 24,
            value: '',
            disabled: true
          },
          {
            label: '工站类型',
            prop: 'routeType',
            type: 'select',
            span: 24,
            disabled: true,
            dicData: this.routeTypes
          },
          {
            label: '是否可跳',
            type: 'switch',
            prop: 'isSkippable',
            formslot: true,
            span: 24
          }
        ]
      },
      firstStep: {},
      firstStepOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '160',
        menuSpan: 6,
        labelPosition: 'top',
        column: [
          {
            label: '标签来源',
            prop: 'lableSource',
            span: 24,
            type: 'select',
            value: 'createSN',
            dicData: [
              {
                label: '自行生成SN',
                value: 'createSN'
              },
              {
                label: '前置单据SN',
                value: 'preSheetSN'
              },
              {
                label: '外部导入SN',
                value: 'ImportSN'
              }
            ],
            change: ({ value }) => {
              console.log(value, 'value');
              if (value == 'createSN') {
                this.firstStep.isImport = true;
                this.firstStep.upperPartNo = '';
                this.firstStep.upperPartMasterId = '';
                this.firstStep.upperPartName = '';
                this.firstStep.ruleCode = '';
                this.firstStep.ruleId = '';
                this.firstStep.ruleName = '';
              } else if (value == 'ImportSN') {
                this.firstStep.isImport = true;
                this.firstStep.upperPartNo = '';
                this.firstStep.upperPartMasterId = '';
                this.firstStep.upperPartName = '';
              } else if (value == 'preSheetSN') {
                this.firstStep.ruleCode = '';
                this.firstStep.ruleId = '';
                this.firstStep.ruleName = '';
              }
            },
            control: (val, form) => {
              if (form.lableSource == 'createSN') {
                return {
                  upperPartName: {
                    display: false
                  },
                  isImport: {
                    display: false
                  }
                  // ruleId: {
                  //   display: false
                  // }
                };
              } else if (form.lableSource == 'preSheetSN') {
                return {
                  upperPartName: {
                    display: true
                  },
                  isImport: {
                    display: false
                  }
                  // ruleId: {
                  //   display: false
                  // }
                };
              } else if (form.lableSource == 'ImportSN') {
                return {
                  upperPartName: {
                    display: false
                  },
                  isImport: {
                    display: true
                  }
                };
              }
            }
          },
          {
            label: '上阶半成品',
            prop: 'upperPartName',
            labelTip: '启用后，该工单可使用所选上阶半成品的SN进行作业。',
            type: 'search',
            span: 24,
            placeholder: '请选择产品编码',
            disabled: true,
            appendClick: () => {
              this.openUserCommonModal({
                type: 'prePart'
              });
            }
          },
          {
            label: '',
            prop: 'isImport',
            type: 'radio',
            span: 24,
            disabled: this.readOnlyPage,
            value: true,
            dicData: [
              {
                label: '已导入SN',
                value: true
              },
              {
                label: '未导入SN',
                value: false
              }
            ],
            control: (val, form) => {
              if (form.isImport) {
                return {
                  ruleName: {
                    display: false
                  }
                };
              } else {
                return {
                  ruleName: {
                    display: true
                  }
                };
              }
            }
          },
          {
            label: '识别规则',
            prop: 'ruleName',
            type: 'search',
            span: 24,
            placeholder: '请选择识别规则',
            disabled: true,
            appendClick: () => {
              this.openUserCommonModal({
                type: 'sequenceDefinitionName'
              });
            }
          }
        ]
      },
      specialInfoOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: '160',
        menuSpan: 6,
        labelPosition: 'top',
        // 过站:OVERSTATION  测试:TEST 报工:TIMESHEET 老化:AGING  组装:ASSEMBLY 包装:PACKING
        column: [
          {
            label: '工站名称',
            prop: 'routeName',
            span: 24,
            value: '',
            disabled: true
          },
          {
            label: '工站类型',
            prop: 'routeType',
            type: 'select',
            span: 24,
            disabled: true,
            dicData: this.routeTypes
          },
          {
            label: '是否开启扣料',
            prop: 'isDeduct',
            type: 'switch',
            span: 24,
            formslot: true,
            control: (val, form) => {
              if (form.routeType == 'OVERSTATION') {
                if (form.isDeduct) {
                  return {
                    isDeduct: {
                      display: true
                    },
                    deductType: {
                      display: true
                    }
                  };
                } else {
                  return {
                    isDeduct: {
                      display: true
                    },
                    deductType: {
                      display: false
                    }
                  };
                }
              } else {
                return {
                  isDeduct: {
                    display: false
                  },
                  deductType: {
                    display: false
                  }
                };
              }
            }
          },
          {
            label: '扣料类型',
            prop: 'deductType',
            type: 'select',
            span: 24,
            formslot: true
          },
          {
            label: '关键物料',
            prop: 'keyPart',
            span: 24,
            formslot: true,
            control: (val, form) => {
              if (form.routeType == 'ASSEMBLY') {
                return {
                  keyPart: {
                    display: true
                  }
                };
              } else {
                return {
                  keyPart: {
                    display: false
                  }
                };
              }
            }
          },
          {
            label: '包装规则',
            prop: 'productPackingConfigName',
            span: 24,
            formslot: true,
            rules: [
              {
                required: true,
                trigger: 'submit',
                validator: (rule, value, callback) => {
                  callback();
                }
              }
            ],
            control: (val, form) => {
              if (form.routeType == 'PACKING') {
                return {
                  productPackingConfigName: {
                    display: true
                  }
                };
              } else {
                return {
                  productPackingConfigName: {
                    display: false
                  }
                };
              }
            }
          },
          {
            label: '老化时间(分)',
            prop: 'agingTime',
            disabled: this.readOnlyPage,
            minRows: '',
            span: 24,
            rules: [
              {
                required: true,
                message: '请输入老化时间',
                trigger: 'blur'
              }
            ],
            control: (val, form) => {
              if (form.routeType == 'AGING') {
                return {
                  agingTime: {
                    display: true
                  }
                };
              } else {
                return {
                  agingTime: {
                    display: false
                  }
                };
              }
            },
            blur: ({ value }) => {
              this.setCurrentStationProperty('agingTime', value);
            }
          },
          {
            label: '老化预警时间(分)',
            prop: 'agingAlertTime',
            disabled: this.readOnlyPage,
            span: 24,
            minRows: '',
            rules: [
              {
                required: true,
                message: '请输入老化预警时间',
                trigger: 'blur'
              }
            ],
            control: (val, form) => {
              if (form.routeType == 'AGING') {
                return {
                  agingAlertTime: {
                    display: true
                  }
                };
              } else {
                return {
                  agingAlertTime: {
                    display: false
                  }
                };
              }
            },
            blur: ({ value }) => {
              this.setCurrentStationProperty('agingAlertTime', value);
            }
          },
          {
            label: '老化比例(百分比)',
            prop: 'agingProportion',
            disabled: this.readOnlyPage,
            span: 24,
            minRows: '',
            value: 100,
            clearable: false,
            control: (val, form) => {
              if (form.routeType == 'AGING') {
                return {
                  agingProportion: {
                    display: true
                  }
                };
              } else {
                return {
                  agingProportion: {
                    display: false
                  }
                };
              }
            },
            blur: ({ value }) => {
              this.setCurrentStationProperty('agingProportion', value);
            }
          },
          {
            label: '工序不良次数',
            prop: 'NgTime',
            disabled: this.readOnlyPage,
            span: 24,
            labelTip: '指测试多少次后都不合格则进入不良登记',
            rules: [
              {
                required: true,
                message: '请输入工序不良次数',
                trigger: 'blur'
              }
            ],
            control: (val, form) => {
              if (form.routeType == 'TEST') {
                return {
                  NgTime: {
                    display: true
                  }
                };
              } else {
                return {
                  NgTime: {
                    display: false
                  }
                };
              }
            },
            blur: ({ value }) => {
              this.setCurrentStationProperty('NgTime', value);
            }
          }
        ]
      },
      selectedSectionIds: [], // 已配置工段id集合
      // 编辑普通物料信息 弹窗配置
      commonPartConfig: {
        title: '',
        visible: false,
        loading: false,
        data: [],
        page: {
          total: 0
        }
      },
      // 编辑关键物料信息 弹窗配置
      keyPartConfig: {
        title: '',
        visible: false,
        loading: false,
        data: [],
        page: {
          total: 0
        }
      },
      isChangeEsopUrl: false,
      workSectionData: [],
      sectionAndRouteList: [],
      isGetAllSection: false,
      modalName: '', //打开公用模态框名称
      tableOption: {}, //公用模态框配置信息
      timer: new Date().getTime(), //不同内容使用同一个模态框结构，key值不同需要重新请求渲染数据，否则会请求到上一个使用的数据内容
      lineInspectionList: [],
      editCheckItemIndex: '',
      isShowCheckItemModal: false,
      checkDetailData: [],
      savedCheckItemList: []
    };
  },
  computed: {
    ...mapState({
      currentStationInfo: (state) => state.design.currentStationInfo,
      allActiveStations: (state) => state.design.allActiveStations
    }),
    // 是否工单工艺路线设计器
    isGdEditorPage() {
      if (this.$route.path.endsWith('pdesign') || this.$route.path.endsWith('pread')) {
        return false;
      } else if (this.$route.path.endsWith('gdesign') || this.$route.path.endsWith('gread')) {
        return true;
      }
    },
    // 路由参数
    routeQuery() {
      return this.$route.query;
    },
    bomId() {
      return this.routeQuery.bomId;
    },
    boxCardStyle() {
      return {
        maxHeight: this.designerBoxHeight
      };
    }
  },
  watch: {
    productData: {
      handler(value) {
        this.newProcessMaterialControlList = value.processMaterialControlList ? JSON.parse(JSON.stringify(value.processMaterialControlList)) : [];
      },
      deep: true
    },
    currentStationInfo: {
      handler(value) {
        // 开始，结束节点，空白区域
        if (!value.routeType) {
          this.initStationInfo();
        }
      },
      deep: true
    },
    // sections: {
    //   handler(value) {
    //     this.sectionAndRouteList = this.getSectionAndRouteList(value);
    //   },
    //   deep: true
    // },
    allActiveStations: {
      handler(value) {
        this.sectionAndRouteList = this.getSectionAndRouteList(this.sections);
        //开线检查配置
        this.lineInspectionList = [];
        this._forEach(value, (item) => {
          let obj1 = this.lineInspectionJson.find((e) => e.sectionId == item.workSectionId);
          let obj2 = this.savedCheckItemList.find((e) => e.sectionId == item.workSectionId);
          if (obj1 || obj2) {
            if (obj1) {
              let checkItemIndex = this._findIndex(this.lineInspectionList, (e) => e.sectionId == obj1.sectionId);
              if (checkItemIndex == -1) {
                this.lineInspectionList.push(obj1);
              }
            }
            if (obj2) {
              let checkItemIndex = this._findIndex(this.lineInspectionList, (e) => e.sectionId == obj2.sectionId);
              if (checkItemIndex == -1) {
                this.lineInspectionList.push(obj2);
              }
            }
          } else {
            let checkItemIndex = this._findIndex(this.lineInspectionList, (e) => e.sectionId == item.workSectionId);
            if (checkItemIndex == -1) {
              this.lineInspectionList.push({
                sectionId: item.workSectionId,
                sectionName: item.workSectionName,
                isEnable: false,
                checkData: [
                  {
                    checkItemType: 'MATERIAL',
                    checkItemList: [
                      {
                        sort: '1',
                        checkItemContent: 'SMT上料是否完成？',
                        checkItemCode: 'SMT_CHECK',
                        isEnable: false
                      },
                      {
                        sort: '2',
                        checkItemContent: '工单上料是否完成？',
                        checkItemCode: 'FEEDING_CHECK',
                        isEnable: false
                      }
                    ]
                  },
                  {
                    checkItemType: 'PERSONNEL',
                    checkItemList: [
                      {
                        sort: '1',
                        checkItemContent: '班组是否已登记？',
                        checkItemCode: 'REGISTER_CHECK',
                        isEnable: false
                      }
                    ]
                  }
                ]
              });
            }
          }
        });
      },
      deep: true
    }
  },
  mounted() {
    this.$store.dispatch('design/getBomTreeDetail', this.bomId);
  },
  methods: {
    initStationInfo() {
      this.activeName = '1';
    },
    getSectionAndRouteList(sections) {
      const that = this;
      let data = [];
      let tempData = {};
      let tracingConfigJson = JSON.parse(that.productData.tracingConfigJson || '[]');
      console.log(tracingConfigJson, 'tracingConfigJson');
      let firstRouteDefinitionJson = JSON.parse(that.productData.firstRouteDefinitionJson || '{}');
      console.log(firstRouteDefinitionJson, 'firstRouteDefinitionJson');
      this.firstStep = firstRouteDefinitionJson;
      // 遍历sections和allActiveStations，按workSectionId分组
      sections.forEach((s) => {
        that.allActiveStations.forEach((a) => {
          if (s.sectionId == a.workSectionId) {
            if (!tempData[a.workSectionId]) {
              tempData[a.workSectionId] = {
                sectionId: a.workSectionId,
                sectionName: s.sectionName,
                sectionCode: s.sectionCode,
                routeId: '',
                routeCode: '',
                routeName: '',
                id: a.id // 当id存在说明已配置过此工序，不存在为新增
              };
            }
          }
        });
      });

      // 将临时对象转换为数组格式
      data = Object.values(tempData);
      if (tracingConfigJson && tracingConfigJson.length > 0) {
        tracingConfigJson.map((trace) => {
          data.map((d) => {
            if (d.sectionId == trace.sectionId && d.id) {
              d.routeId = trace.routeId;
              d.routeName = trace.routeName;
              d.routeCode = trace.routeCode;
            }
          });
        });
      }
      return data;
    },
    getRouteList(sectionId) {
      let findList = this.allActiveStations.filter((item) => item.workSectionId == sectionId);
      return findList.map((f) => {
        return {
          routeId: f.workstationId,
          routeCode: f.routeCode,
          routeName: f.routeName
        };
      });
    },
    changeRoute(value, index) {
      console.log(value, index);
      let find = this.allActiveStations.find((item) => item.workstationId == value);
      this.sectionAndRouteList[index].routeCode = find.routeCode;
      this.sectionAndRouteList[index].routeName = find.routeName;
    },
    getWorkSectionByPart(id) {
      getSectionByPartId(id).then((res) => {
        let data = this._get(res, 'data.data.sections', []);
        const workSectionData = this.findObject(this.basicInfoOption.column, 'workSectionId');
        if (data != null && data.length != 0) {
          this.workSectionData = data;
          workSectionData.dicData = this._map(this.workSectionData, (item) => {
            return {
              label: item.sectionName,
              value: JSON.stringify(item)
            };
          });
        } else {
          workSectionData.dicData = [];
        }
      });
    },
    // 设置currentStationInfo的属性并更新工站信息
    setCurrentStationProperty(key, value) {
      // 过站:OVERSTATION  测试:TEST 报工:TIMESHEET 老化:AGING  组装:ASSEMBLY 包装:PACKING
      this.$set(this.currentStationInfo, key, value);
      if (this.currentStationInfo.processRouteConfigList && this.currentStationInfo.processRouteConfigList.length > 0) {
        this.currentStationInfo.processRouteConfigList.forEach((route) => {
          if (route.key == key) {
            route.value = value;
          }
        });
      }
      console.log(this.currentStationInfo, 'currentStationInfo');
      this.$store.commit('design/setCurrentStationInfo', this.currentStationInfo);
      this.$store.commit('design/changeAllActiveStations', this.currentStationInfo);
    },
    close(name) {
      this[name].visible = false;
    },
    //  右侧配置面板
    openEditNodeModal(operation) {
      this.openCustomModal(operation);
    },
    /**
     *物料信息弹框
     */
    openCustomModal(operateName) {
      if (operateName == 'keyPartConfig') {
        if (!this.productProcessId) {
          if (this.currentStationInfo.id) {
            let keyPartConfigData = structuredClone(this.currentStationInfo.assembleKeyMaterialConfigList);
            getKeyMaterialConfigByRouteId(this.currentStationInfo.id).then(
              (res) => {
                let data = this._get(res, 'data.data', []);
                keyPartConfigData.forEach((keyData) => {
                  data.forEach((dItem) => {
                    if (keyData.id == dItem.id) {
                      keyData.partSpec = dItem.partSpec;
                    }
                  });
                });
                this.keyPartConfig.data = keyPartConfigData;
              },
              (error) => {
                this.keyPartConfig.data = [];
              }
            );
          } else {
            this.keyPartConfig.data = structuredClone(this.currentStationInfo.assembleKeyMaterialConfigList);
          }
        } else if (this.productProcessId && this.currentStationInfo.routeCode) {
          getKeyMaterialConfigByProcessId(this.productProcessId, this.currentStationInfo.routeCode).then(
            (res) => {
              this.keyPartConfig.data = this._get(res, 'data.data', []);
            },
            (error) => {
              this.keyPartConfig.data = [];
            }
          );
        } else {
          this.keyPartConfig.data = [];
        }
        this[operateName].title = '关键料追溯配置表';
        this[operateName].visible = true;
      }
      if (operateName == 'commonPartConfig') {
        this.commonPartConfig.data = this.newProcessMaterialControlList;
        this[operateName].title = `普通物料信息`;
        this[operateName].visible = true;
      }
    },
    changeProcessMaterialControlList(value) {
      this.$emit('submitProcessMaterialControlList', value);
    },
    // 重置节点连接顺序
    resetOrder(json) {
      try {
        let linkDataArray = json.linkDataArray;
        let nodeDataArray = json.nodeDataArray;
        let newNodeDataArray = nodeDataArray.filter((node) => node.key == 'Start' || node.key == 'End');
        let startNode = linkDataArray.filter((data) => data.from == 'Start');
        let startNodeTo = null;
        let nextNode = null;
        if (startNode && startNode.length > 0) {
          startNodeTo = startNode[0].to;
          if (startNodeTo != 'End') {
            nextNode = nodeDataArray.find((node) => node.key && node.key == startNodeTo);
            if (nextNode) newNodeDataArray.push(nextNode);
          }
        }
        if (nextNode) {
          let newNodeList = order(nextNode.key, newNodeDataArray);
          function order(nextNodeKey, node) {
            let nextNode = linkDataArray.filter((data) => data.from == nextNodeKey);
            let nextNodeTo = null;
            if (nextNode && nextNode.length > 0) {
              nextNodeTo = nextNode[0].to;
              if (nextNodeTo != 'End') {
                let nextData = nodeDataArray.find((node) => node.key && node.key == nextNodeTo);
                if (nextData) node.push(nextData);
                order(nextData.key, node);
              }
            }
            return node;
          }
          json.nodeDataArray = newNodeList;
        }
        return json;
      } catch (error) {
        console.log(error);
      }
    },
    clearProductPackingConfigName() {
      this.currentStationInfo.productPackingConfigId = '';
      this.currentStationInfo.productPackingConfigName = '';
    },
    getPackWeightInfo(productPackingConfigId) {
      getPackingDetail(productPackingConfigId).then((res) => {});
    },
    openUserCommonModal(params) {
      let { type } = params;
      switch (type) {
        case 'prePart':
          this.$refs.prePartRef.showModal();
          this.modalName = 'partModal';
          break;
        // 物料编码
        case 'productCode':
          this.modalName = 'partmasterModal';
          this.visibile = true;
          this.tableOption = {
            modalTitle: '添加物料信息',
            url: `/api/mes-admin/bom/detail/part-page?bomId=${this.$route.query.bomId}`,
            isPage: true,
            query: {
              // semifinished: false
              // partType: 'SEMIFINISHED'
            },
            rowSelectionType: 'multiple',
            menuWidth: 100,
            templateName: 'PARTMASTER'
          };
          break;
        // 包装配置
        case 'packingConfig':
          this.modalName = 'packingConfigModal';
          this.visibile = true;
          this.tableOption = {
            modalTitle: '选择包装配置（双击进行选择）',
            url: `/api/mes-admin/product/packing/config/page?parentId=0&productPartNo=${this.$route.query.partNo}`,
            isPage: true,
            lazy: true,
            hasChildren: 'isHasSubPack',
            lazyTreeUrl: '/api/mes-admin/product/packing/config/query/direct/children/by/parentId',
            rowSelectionType: 'single',
            templateName: 'PACKINGCONFIG'
          };
          break;
        // 条码规则
        case 'sequenceDefinitionName':
          this.modalName = 'serialnoModal';
          this.visibile = true;
          this.tableOption = {
            modalTitle: '选择序列号规则（双击进行选择）',
            url: '/api/mes-admin/sequencedefinition/page',
            isPage: true,
            rowSelectionType: 'single',
            templateName: 'SERIALNO'
          };
          break;
        default:
          break;
      }
    },
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'partModal':
          console.log('rowData', rowData, rowData.tableType);
          if (rowData.tableType === '1') {
            this.$set(this.firstStep, 'upperPartNo', rowData.partNo);
            this.$set(this.firstStep, 'upperPartMasterId', rowData.partMasterId);
            this.$set(this.firstStep, 'upperPartName', rowData.partName);
          } else if (rowData.tableType === '2') {
            this.$set(this.firstStep, 'upperPartNo', rowData.partNo);
            this.$set(this.firstStep, 'upperPartMasterId', rowData.partMasterId);
            this.$set(this.firstStep, 'upperPartName', rowData.partName);
          } else if (rowData.tableType === '3') {
            this.$set(this.firstStep, 'upperPartNo', rowData.partNo);
            this.$set(this.firstStep, 'upperPartMasterId', rowData.id);
            this.$set(this.firstStep, 'upperPartName', rowData.name);
          }
          break;
        case 'serialnoModal':
          this.$set(this.firstStep, 'ruleCode', rowData.code);
          this.$set(this.firstStep, 'ruleId', rowData.id);
          this.$set(this.firstStep, 'ruleName', rowData.name);
          break;
        case 'partmasterModal':
          this.$nextTick(() => {
            this.visibile = false;
            let deepCloneCurrentStationInfo = JSON.parse(JSON.stringify(this.currentStationInfo));
            let options = JSON.parse(deepCloneCurrentStationInfo['options'] || '{}');
            deepCloneCurrentStationInfo['options'] = JSON.stringify(options);
            // 重新设置当前选中工站信息
            this.$store.commit('design/setCurrentStationInfo', deepCloneCurrentStationInfo);
            //  重新设置所有有效工序信息;
            this.$store.commit('design/changeAllActiveStations', deepCloneCurrentStationInfo);
          });
          break;
        case 'packingConfigModal':
          this.$set(this.currentStationInfo, 'productPackingConfigId', rowData.id);
          this.$set(this.currentStationInfo, 'productPackingConfigName', rowData.name);
          this.setCurrentStationProperty('productPackingConfigId', rowData.id);
          this.setCurrentStationProperty('productPackingConfigName', rowData.name);
          break;
        default:
          break;
      }
    },
    // 重新加载公用表格弹窗组件
    newKey() {
      this.timer = new Date().getTime();
    },
    sectionSwitchChange(value, index) {
      if (!value) {
        this.lineInspectionList[index].checkData = [
          {
            checkItemType: 'MATERIAL',
            checkItemList: [
              {
                sort: '1',
                checkItemContent: 'SMT上料是否完成？',
                checkItemCode: 'SMT_CHECK',
                isEnable: false
              },
              {
                sort: '2',
                checkItemContent: '工单上料是否完成？',
                checkItemCode: 'FEEDING_CHECK',
                isEnable: false
              }
            ]
          },
          {
            checkItemType: 'PERSONNEL',
            checkItemList: [
              {
                sort: '1',
                checkItemContent: '班组是否已登记？',
                checkItemCode: 'REGISTER_CHECK',
                isEnable: false
              }
            ]
          }
        ];
      }
    },
    openEditCheckItem(index) {
      this.isShowCheckItemModal = true;
      this.editCheckItemIndex = index;
      this.checkDetailData = this.lineInspectionList[index].checkData;
    },
    submitCheckItem(data) {
      this.lineInspectionList[this.editCheckItemIndex].checkData = data;
      if (this.savedCheckItemList[this.editCheckItemIndex]) {
        this.savedCheckItemList[this.editCheckItemIndex] = this.lineInspectionList[this.editCheckItemIndex];
      } else {
        this.savedCheckItemList.push(this.lineInspectionList[this.editCheckItemIndex]);
      }
      this.isShowCheckItemModal = false;
    },
    closeCheckItemModal() {
      this.isShowCheckItemModal = false;
    }
  }
};
</script>
<style scoped lang="scss">
.box-card {
  height: 100%;
  max-height: calc(100vh - 260px);
  overflow: scroll;

  ::v-deep .el-collapse-item__header {
    background: linear-gradient(180deg, #5c5c5c 0%, #3f3e3e 56%, #191919 100%);
    color: #fff;
    padding: 0 0 0 10px;
    font-weight: bold;
  }
  ::v-deep .el-collapse-item__wrap {
    .el-collapse-item__content {
      padding-bottom: 0;
      .traceContainer {
        padding: 5px;
        .title {
          font-weight: bold;
          margin-bottom: 5px;
        }
        .row {
          margin-bottom: 8px;
        }
      }
    }
  }
}

.nav-tab {
  ::v-deep .el-tabs__content {
    overflow: auto;
  }
  ::v-deep .el-tabs__item {
    padding: 0;
    width: 90px;
    text-align: center;
  }
  ::v-deep .el-form--label-top .el-form-item__label {
    padding: 0;
  }
  .el-tab-pane {
    padding: 0 5px;
  }
  .border-title {
    border-left: 5px solid #5a93bb;
    border-bottom: 2px dashed #ccc;
    font-weight: 700;
    padding-left: 5px;
    font-size: 15px;
  }
  .addCheckBtn {
    width: 95%;
    margin-left: 10px;
  }
  .check-item-content {
    width: 95%;
    margin: 10px;
    ::v-deep .clearfix {
      font-size: 15px;
      font-weight: bold;
    }
    .isCheck-item-content {
      word-break: break-all;
      padding: 5px 8px;
    }
  }
  .customOperateBtn {
    text-align: center;
  }
}
.switch-with-button {
  .el-button {
    margin-left: 50px;
  }
}
.sectionOnLinetitle {
  font-weight: bold;
  margin-bottom: 5px;
}
.sectionOnLineConfig {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  margin-right: 5px;
  .sectionSwitch {
    display: flex;
    align-items: center;
  }
  button {
    height: 32px;
  }
}
</style>
